package com.xiaowen.tool;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * User: yf-wenhao
 * Date: 2024/9/19
 * Time: 上午9:21
 */
@Slf4j
public class SmsUtil {

    public static void send(String phoneNumber, String code) {
        String TCC_SECRET_ID = "AKIDb2GG8lDUWNyKRTLuIQL2VjncHgplCzMb";
        String TCC_SECRET_KEY = "9oDMIzRdgU8XgdKn17ynSr3zg7OQH2Xp";
        Credential credential = new Credential();
        credential.setSecretId(TCC_SECRET_ID);
        credential.setSecretKey(TCC_SECRET_KEY);
        SmsClient sms = new SmsClient(credential, "ap-beijing");
        SendSmsRequest req = new SendSmsRequest();
        req.setPhoneNumberSet(new String[]{phoneNumber});
        req.setSmsSdkAppId("1400861847");
        req.setTemplateId("2048833");
        req.setSignName("北京在问科技有限公司");
        req.setSessionContext("34343");
        req.setTemplateParamSet(new String[]{code});
        try {
            log.info("发送验证码 请求参数 ---- {}", JsonUtils.toJson(req));
            SendSmsResponse sendSmsResponse = sms.SendSms(req);
            log.info("发送验证码 返回结果--- {}", JsonUtils.toJson(sendSmsResponse));
        } catch (Exception e) {
            log.error("发送验证码 报错--- ", e);
        }
    }
}
